﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="hrSetExaminationRole.aspx.cs" Inherits="ZX.WebApp.EHR.hrSetExaminationRole" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>设置考核角色</title>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <script src="../Scripts/jquery-1.6.min.js" type="text/javascript"></script>
    <script src="../Scripts/jquery.json-2.2.min.js" type="text/javascript"></script>
    <script src="../Scripts/Jquery.form.js" type="text/javascript"></script>
     <script type="text/javascript" src="../Scripts/CombinButton.js"></script>
     <script src="../Scripts/DatePicker/WdatePicker.js" type="text/javascript"></script>
    <link href="../Styles/extendTable.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript">
    // <![CDATA[
            var fun = "";
            $(document).ready(function () {
                var objectID = getPar1("objectID");
                var objectEmpName = getPar1("objectEmpName");
                var objectEmpID = getPar1("objectEmpID");
                var objectEmpCode = getPar1("objectEmpCode");
                fun = getPar1("fun");
                $("#ObjectID").val(objectID);
                $("#ObjectEmpName").val(objectEmpName);
                $("#ObjectEmpID").val(objectEmpID);
                $("#ObjectEmpCode").val(objectEmpCode);
                if (fun == "view") {
                    $("div input").attr("disabled", true).css("background", "whitesmoke");
                    $("div textarea").css("background", "whitesmoke");
                    $("div select").attr("disabled", true).css("background", "whitesmoke");
                    $("div input[type=button]").hide();
                }
                else {
                    parent.document.getElementById("dialog1_h").innerHTML = objectEmpName + "_设置考核角色";
                }
                GetExaminationRole(objectID);
            });

            //取得已存在的数据
            function GetExaminationRole(objectID) {
                var url = "../Extend/AjaxData/jsonlist.aspx?entity=ExaminationRole&condition=ObjectID='" + objectID + "'";
                $.get(url, function (d, s) {
                    var list = eval("(" + d + ")");
                    var i = 0;
                    if (list.rows.length > 0) {
                        for (var o in list.rows) {
                            //debugger;
                            var t = list.rows[o].ID;
                            if (typeof (t) != "undefined") {
                                //加载行
                                addtr();
                                //加载数据
                                var lastTr = $("#tbEmp tr").last();
                                $("#EmployeeID", lastTr).val(list.rows[o].EmployeeID);
                                $("#PostID", lastTr).val(list.rows[o].PostID);
                                $("#Weight", lastTr).val(list.rows[o].Weight);
                                GetEmpInfoByEmpID(list.rows[o].EmployeeID, lastTr);
                                RoleIsAppraiseFinish(objectID,list.rows[o].EmployeeID, lastTr);
                            }
                        }
                    }
                    else {
                        //加载行
                        addtr();
                    }
                });
            }

            //判断一个考核计划是否考核完毕
            function RoleIsAppraiseFinish(objectID, roleEmpID, lastTr) {
                YAHOO.util.Connect.asyncRequest('POST', "hrExaminationAjax.aspx?flag=roleisappraisefinish&objectID=" + objectID + "&roleEmpID=" + roleEmpID, {
                    success: function (res) {
                        try {
                            var str = res.responseText;
                            if (str == "Y") {
                                $(lastTr).attr("disabled", true).css("background", "whitesmoke");
                                $("#btnempId", lastTr).hide();
                            }
                            $("#IsAppraiseFinish", lastTr).val(str);
                            $("#spanIsAppraiseFinish", lastTr).html(str);
                        }
                        catch (e) {
                        }
                        finally {
                        }
                    },
                    failure: function (error) {
                        alert("数据错误：" + error.statusText);
                    }
                }, null);
            }

            //选择员工
            var employeeId;
            var ValueChanged = function (rowobj) {
                employeeId = $("#empId").val();
            }

            var TextChanged = function (rowobj) {
                var employeeName = $("#txtempId").val();
                if (employeeId == "" || employeeId == "undefined") {
                    return;
                }
                if (employeeName == "" || employeeName == "undefined") {
                    return;
                }
                //debugger
                $("#txtEmployeeID", rowobj).val(employeeName);
                $("#EmployeeID", rowobj).val(employeeId);
                GetEmpInfoByEmpID(employeeId, rowobj);
            }

            //获取员工信息，所属岗位名称、员工编号、员工姓名
            function GetEmpInfoByEmpID(empId, rowobj) {
                var url = "../Extend/AjaxData/jsonlist.aspx?entity=V_hrEmployee&condition=ID='" + empId + "'";
                $.get(url, function (d, s) {
                    var list = eval("(" + d + ")");
                    for (var o in list.rows) {
                        var t = list.rows[o].EmployeeCode;
                        if (typeof (t) != "undefined") {
                            $("#PostName", rowobj).val(list.rows[o].PostName);
                            $("#PostID", rowobj).val(list.rows[o].PostID);
                            $("#EmployeeCode", rowobj).val(t);
                            $("#txtEmployeeID", rowobj).val(list.rows[o].CName);
                        }
                    }
                });
            }

            //增加行
            function addtr() {
                var tr = $("#tbEmp tr").eq(1).clone();
                tr.show();
                tr.appendTo("#tbEmp").find(":checkbox").attr("checked", false);
            }

            //删除行
            function deltr() {
                //遍历tr
                $("#tbEmp tr").first().nextAll().each(function () {
                    if ($(this).find(":checkbox").attr("checked")) {
                        $(this).remove();
                    }
                });
            };

            //选中行
            $("#tbEmp tr").live("click", function () {
                if ($(this).find(":checkbox").attr("checked")) {
                    $(this).find(":checkbox").attr("checked", false);
                } else {
                    $(this).find(":checkbox").attr("checked", true);
                }
            });

            //数据保存
            function Save() {
                //debugger;
                var objectID = $("#ObjectID").val();
                //存储行中的数据
                var _TempArray = [];

                if (objectID == "") {
                    alert("考核对像为空！");
                    return;
                }

                //遍历所有已选择员工
                $("#tbEmp tr").eq(1).nextAll().each(function () {
                    var id = $("#EmployeeID", this).val();
                    var IsAppraiseFinish = $("#IsAppraiseFinish", this).val();
                    if (id != "") {
                        _TempArray.push($(this).extractObject());
                    }
                });

                if (_TempArray.length == 0) {
                    alert("请至少选择一个考核角色！");
                    return;
                }

                //将行转成JSON
                var json = $.toJSON(_TempArray);
                var Url = "hrExaminationAjax.aspx?flag=saveexaminationrole&json=" + encodeURI(json) + "&id=" + encodeURI(objectID);

                //提交数据
                YAHOO.util.Connect.asyncRequest('POST', Url, {
                    success: function (res) {
                        try {
                            var str = res.responseText;
                            if (str.substring(0, 1) == "1") {
                                alert("数据保存成功!");
                                parent.closeWin();
                            }
                            else {
                                alert("数据保存失败,请检查");
                            }
                        }
                        catch (e) {
                        }
                        finally {
                        }
                    },
                    failure: function (error) {
                        alert("数据错误：" + error.statusText);
                    }
                }, null);
            }
    // ]]> 
     </script>
    <style type="text/css">
        body{font-family: 宋体, Arial, Helvetica, sans-serif;font-size: 12px;color: #333333;background-color: #FFFFFF;} 
        select{width:99%;} td { border: 1px solid #CCCCCC;}
        .textarea{ width: 96%;height: 25px;}	
        .selectedTr{  background-color: blue;} 
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <input type="hidden" id="ObjectID" name="ObjectID" />
    <input type="hidden" id="ObjectEmpName" name="ObjectEmpName" />
    <input type="hidden" id="ObjectEmpID" name="ObjectEmpID" />
    <input type="hidden" id="ObjectEmpCode" name="ObjectEmpCode" />
    <input id="empId" name="empId" type="hidden" />
    <input id="txtempId" name="txtempId" type="hidden" />
    <div id="divBtn">
        <input type="button" id="btnADD" value="新增" onclick="addtr();" />
        <input type="button" id="btnDEL" value="删除" onclick="deltr();" />
    </div>
    <table align="center" border="1" id="tbEmp" name="tbEmp" style="border-collapse: collapse" width="99%">
        <tr id="data_head" style="background-color: #e4e7e2">
           <td style="text-align: center"></td>
	        <td style="text-align: center">考核者姓名</td>
	        <td style="text-align: center">考核者编号</td>
	        <td style="text-align: center"> 考核者岗位</td>
	        <td style="text-align: center"> 所占权重(%)</td>
	        <td style="text-align: center"> 已考核</td>
        </tr>
        <tr style="display:none">
            <td>
                <input type="checkbox" id="chktr" name="chktr" convert="unconvert" />
            </td>
	        <td>
		        <input  id="EmployeeID" name="EmployeeID" type="hidden" value="" />
                <input  id="txtEmployeeID" name="txtEmployeeID" readonly="readonly" style="border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent;background:whitesmoke;" type="text" convert="unconvert" />
                <button id="btnempId" name="emp" onclick="SelectEmployee(this);" type="button" convert="unconvert">选择</button>
            </td>
	        <td>
		        <input  id="EmployeeCode" name="EmployeeCode" readonly="readonly" style="border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent;background:whitesmoke;" type="text" convert="unconvert"/>
            </td>
	        <td>
		        <input id="PostID" name="PostID" readonly="readonly" style="border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent" type="hidden" />
		        <input id="PostName" name="PostName" readonly="readonly" style="border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent;background:whitesmoke;width:90%;" type="text" convert="unconvert" />
            </td>
	        <td>
		        <input id="Weight" name="Weight"  style="border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent" type="text" value="0.0"  onblur="IsValidateFloat(this);"/>
            </td>
            <td>
            <input id="IsAppraiseFinish" name="IsAppraiseFinish" type="hidden" value="N" convert="unconvert"/>
            <span id="spanIsAppraiseFinish" convert="unconvert">N</span>
            </td>            
        </tr>
    </table>
    </div>
    </form>
</body>
</html>
